home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 04 / commclnt.pas < prev    next >
Pascal/Delphi Source File  |  1991-05-13  |  4KB  |  142 lines

  1. {*****************************************************************************
  2. ** Communications Client Version 1.0                            May 1, 1991 **
  3. ** Copyright 1987,1988,1991 by L. Brett Glass, Systems Consultant           **
  4. ******************************************************************************}
  5. program Client; {Client TSR}
  6. uses NetBIOS,NetTools,DOS;
  7.  
  8. {$M 8192,0,0} {Use 8K of stack, no heap}
  9. {$R-}
  10. {$S-}
  11. {$I-}      {Turn off space- and time-consuming options}
  12. {$V-}
  13.  
  14. type
  15.   PortNumType = 1..4;
  16.  
  17. type
  18.   CommRegType = record
  19.     case Boolean of
  20.       TRUE: (dx,cx,bx,ax : Word);
  21.       FALSE: (dl,dh,cl,ch,bl,bh,al,ah : Byte);
  22.     end;
  23.  
  24. var
  25.   myPermNodeName, remotePortName : NetName;
  26.   biosPortNum : PortNumType;
  27.   commSessionNum : Byte;
  28.   oldInt14 : Pointer;
  29.   clientSendBlock,clientRcvBlock : NCB;
  30.   saveStackSeg : Word;
  31.   saveStackPtr : Word;
  32.  
  33. const
  34.   ERRORFLAG = $80; {Flag to indicate comm timeout or error}
  35.  
  36. procedure ValidateParms;
  37.   var
  38.     tempStr : String;
  39.   begin
  40.   if ParamCount <> 2 then
  41.     begin
  42.     Writeln('Usage: CLIENT <Network Name> <Port Number>');
  43.     Writeln(' E.G.: CLIENT MyModem 2');
  44.     Writeln('       Connects COM2: to a remote networked');
  45.     Writeln('        communications port with the name MyModem');
  46.     Halt
  47.     end;
  48.   tempStr := ParamStr(1);
  49.   if (Length(tempStr) = 0) or (Length(tempStr) > 16) then
  50.     begin
  51.     Writeln('Error: Serial port/modem name must be 1 to 16 characters');
  52.     Halt
  53.     end;
  54.   FillChar(remotePortName,SizeOf(remotePortName),' ');
  55.   Move(tempStr[1],remotePortName[1],Length(tempStr));
  56.   tempStr := ParamStr(2);
  57.   if (Length(tempStr) <> 1) or (tempStr[1] < '1') or
  58.     (tempStr[1] > '4') then
  59.     begin
  60.     Writeln('Error: Port number must be 1 through 4');
  61.     Halt
  62.     end;
  63.   biosPortNum := Ord(tempStr[1])-Ord('1'); {BIOS uses 0=COM1, etc.}
  64.   end; {ValidateParms}
  65.  
  66. procedure Connect;
  67.   begin
  68.   if not NetBIOSPresent then
  69.     begin
  70.     Writeln('Error: NetBIOS not available');
  71.     Halt;
  72.     end;
  73.   if NetToolsGetMyName(myPermNodeName) <> GOOD_RTN then
  74.     begin
  75.     Writeln('Error: Unable to determine adapter status');
  76.     Halt;
  77.     end;
  78.   {Do a call. Set up a session with five-second timeouts.}
  79.   if NetToolsCall(myPermNodeName,remotePortName,10,10,commSessionNum) <> GOOD_RTN then
  80.     begin
  81.     Writeln('Error: Unable to establish session with server');
  82.     Halt;
  83.     end;
  84.   {Initialize NCBs for the conversation}
  85.   clientSendBlock.Init(SEND);
  86.   clientRcvBlock.Init(RECEIVE);
  87.   end; {Connect}
  88.  
  89. procedure Int14Handler(flags,cs,ip,ax,bx,cx,dx,si,di,ds,es,bp : Word);
  90.   interrupt;
  91.   {All Int 14 requests are sent off to the server for processing.
  92.    The server takes care of queueing, returning status, etc.
  93.    Note that this code doesn't filter out invalid function codes;
  94.    this allows us to add functionality at the server without
  95.    changing the basic client.}
  96.   var
  97.     commRegs : CommRegType absolute dx;
  98.   begin
  99.   if dx <> biosPortNum then {Chain to old vector}
  100.     asm
  101.     mov sp,bp
  102.     pop bp; pop es; pop ds; pop di; pop si;
  103.     pop dx; pop cx; pop bx; pop ax;
  104.     jmp oldInt14;
  105.     end
  106.   else
  107.     begin
  108.     asm sti end; {Turn on interrupts}
  109.     with clientSendBlock do
  110.       begin
  111.       bufPtr := Addr(commRegs);
  112.       lsn := commSessionNum;
  113.       len := SizeOf(CommRegType);
  114.       if ReturnCode = GOOD_RTN then
  115.         with clientRcvBlock do
  116.           begin
  117.           bufPtr := Addr(commRegs); {Point to block with dx,cx,bx,ax}
  118.           len := SizeOf(commRegs); {Four words long}
  119.           lsn := commSessionNum;
  120.           if (ReturnCode <> GOOD_RTN) or (len <> SizeOf(commRegs)) then
  121.             commRegs.ah := retcode or ERRORFLAG; {Slip in NetBIOS error code}
  122.           end
  123.       else {If send failed}
  124.         commRegs.ah := retcode or ERRORFLAG;
  125.       end
  126.     end {case ah}
  127.   end; {Int14Handler}
  128.  
  129. procedure DivertInt14;
  130.   begin
  131.   GetIntVec($14,oldInt14);
  132.   SetIntVec($14,Addr(Int14Handler));
  133.   end; {DivertInt14}
  134.  
  135. begin {Client}
  136. ValidateParms; {Check and parse command line}
  137. Connect;
  138. DivertInt14; {Capture INT 14 so we can provide services}
  139. SwapVectors; {Prepare to go resident}
  140. Keep(0); {Go resident}
  141. end. {Client}
  142.